<HTML>
<HEAD>
<TITLE>
Disk Space Monitor
</TITLE>
<HEAD>
<BODY>
<?
	include "DFData.php" ;
	include "SSHSession.php" ;
	include "mysql.php"; 
	
	$mysql = new MySQL();
	$hostlist = $mysql->getHostList() ;
	
	$mysql->execute("truncate table realtime");
	foreach($hostlist as $host)
	{
		$dfcommand = "df -k | grep /dev/[s,h]d." ; //default
		if ( isset($hostlist["dfcommand"]))
			if ($hostlist["dfcommand"] != "")
				$dfcommand = $hostlist["dfcommand"] ;
		
		$c = new SSHSession();
		$dfdata = new DFData($host["id"],$host["name"]);
		$c->connect($host["hostname"],$host["username"],$host["password"]);
		if(!$c->ok) {
			echo "<bWarning</b>host :".$host["hostname"]." error" ;
			$query = "insert into history("; 
			//skiping to next host
		}
		else
		{
			$c->exec($dfcommand);
			while(!$c->EOF())
			{
				$dfline = $c->readln();
				$dfdata->decodeDF($dfline) ;
			}
			//Insert to History Table
			$historyInsertQuery = $dfdata->makeInsertQuery();
			$mysql->execute($historyInsertQuery);
			//Insert to RealTime Table
			$realTimeInsertQuery = ereg_replace("history","realtime",$historyInsertQuery);
			$mysql->execute($realTimeInsertQuery);
			$dfdata->show();
		}
	}
?>
</BODY>
</HTML>